<template>
    <div style=" position: relative;"><el-card>
            <template #header>
                <!-- 搜索 -->
                <div>


                    <el-select style="width: 300px;" v-model="find_data.templatesInfoId" placeholder="请选择模版名称">
                        <el-option v-for="item in findTemplatesInfoNameCombo_list" :key="item.id"
                            :label="item.templates_name" :value="item.id" />

                    </el-select>
                    <el-input style="width: 180px;margin-left: 20px;" v-model="find_data.storeName"
                        placeholder="请输入名店名称" clearable prefix-icon="Search" />

                    <el-select v-model="find_data.companyNum" placeholder="请选择查询单位" filterable clearable
                        style="width: 220px;margin-left: 20px;">
                        <el-option v-for="(ct, index) in getCompanyCombo_list " :key="index" :label="ct.company_name"
                            :value="ct.company_num">
                            <span style="float: left">{{ ct.company_name }}</span>
                            <span style="
                            float: right;
                            color: var(--el-text-color-secondary);
                            font-size: 13px;
                          ">{{ ct.company_num }}</span>
                        </el-option>
                    </el-select>
                    <el-select clearable @change='seats_change1' style="width: 160px;margin-left: 20px;"
                        v-model="find_data.seats" placeholder="请选择座位数">
                        <el-option v-for="item in seats_list" :key="item.value" :label="item.label"
                            :value="item.value" />

                    </el-select>

                    <el-select clearable @change="carConfigurationType_change1" style="width:350px;margin-left: 20px;"
                        v-model="find_data.carConfigurationType" placeholder="请选择车辆配置">
                        <el-option v-for="item in getCarConfigurationType_list2" :key="item.id"
                            :label="item.val + '(' + item.other + ')'" :value="item.id" />
                    </el-select>
                    <el-button style="margin-left: 20px;height:30px" @click="search_btn" type="primary"
                        icon="Search">搜索</el-button>
                </div>
                <!-- 功能按钮 -->
                <div style="margin-top:10px;">
                    <el-button @click="add_btn" type="primary" icon="SuccessFilled">添加</el-button>
                    <el-button @click="up_btn" type="warning" icon="WarnTriangleFilled">修改</el-button>
                    <el-button @click="del_btn" type="danger" icon="CircleCloseFilled">删除</el-button>
                    <el-button @click="BcProfitSet_btn" type="primary" icon="CircleCloseFilled">设置包车利润</el-button>
                </div>
            </template>
            <div>
                <el-table border @selection-change="selection_change_btn" height="67vh" ref="multipleTableRef"
                    :data="list_data" style="width: 100%">
                    <el-table-column type="selection" width="35" />
                    <el-table-column label="编号" width="55" fixed type="index" />
                    <template v-for="item in table_data_list_new" :key="item.field">
                        <el-table-column v-if="item.off" :width="item.width" :prop="item.field" :label="item.label">
                            <template v-if="item.field == 'carConfigurationType'" #="{ row, column, $index }">
                                <span>{{ row.carConfigurationType == 'ECONOMICAL' ? '经济型' : row.carConfigurationType ==
                                    'COMFORTABLE' ? '舒适型' : row.carConfigurationType == 'LUXURY' ? '豪华型' :
                                    row.carConfigurationType ==
                                        'BUSINESS_NANNY_CAR' ? '商务保姆车' : row.carConfigurationType ==
                                            'ECONOMICAL_MIDDLE_CAR' ? '经济中巴' : row.carConfigurationType ==
                                                'COMFORTABLE_MIDDLE_CAR' ? '舒适中巴' : row.carConfigurationType ==
                                                    'LUXURY_MIDDLE_CAR' ? ' 豪华中巴' : row.carConfigurationType ==
                                                        'MIDDLE_NANNY_CAR' ? '中巴保姆车' : row.carConfigurationType ==
                                                            'TRAVEL_LARGE_CAR' ? '旅游大巴' : row.carConfigurationType ==
                                                                'LARGE_NANNY_CAR' ? '大巴保姆车' : '暂无'
                                    }}</span>

                            </template>


                        </el-table-column>
                    </template>
                </el-table>
            </div>

            <div style="margin-top:20px">
                <el-pagination @current-change="current_change_btn" @size-change="size_change_btn"
                    v-model:current-page="find_data.page.pageNum" v-model:page-size="find_data.page.pageSize"
                    :page-sizes="[20, 50, 100, 200]" :background="true"
                    layout="prev, pager, next, jumper,->,sizes,total," :total="total" />
            </div>
        </el-card>
    </div>

    <!-- 弹窗 -->
    <div>
        <!-- 表格筛选 -->
        <div style="position: absolute;top:75px;z-index: 2;" :style="icon_off ? 'right:0px;' : 'right:110px;'">
            <el-icon @click="icon_btn" :size="20">
                <Setting />
            </el-icon>
            <div v-show="icon_off"
                style=" position: relative;top:-100px;right:140px;width: 130px;height:430px;background:#fff;overflow: hidden;">
                <div class="cols-set" style="background:#fff;width:90%;height:97%;margin:auto;margin-top:10px;">
                    <div>
                        <el-button-group style="display: flex; ">
                            <el-tooltip effect="dark" placement="bottom">
                                <template #content>注意：拖动下面的项，可以改变表格列的顺序，<br />记得点击保存才会永久生效哦！ </template>
                                <el-button style="width:10px" type="primary" icon="WarningFilled"></el-button>
                            </el-tooltip>
                            <el-button title="重置" type="primary" icon="Refresh" @click="resetTableSet"></el-button>
                            <el-button title="保存" type="primary" icon="Check" @click="saveTableSet"></el-button>
                        </el-button-group>
                        <div ref="sortableContainer" class="col-items" style="height:400px; overflow-y: auto; ">
                            <el-checkbox class="drag_it" @change="checkbox_btn" v-for="item in sortedItems"
                                :key="item.field" v-model="item.off" :label="item.label" border>
                            </el-checkbox>
                        </div>

                    </div>
                </div>
            </div>
        </div>
        <!-- 添加修改 -->
        <el-dialog style="margin-top:5vh" v-model="add_off" :title="title" width="65%" :close-on-click-modal='false'>
            <el-form :model="add_data" label-width="140px" label-suffix="：">


                <el-row>
                    <el-col :span="8">
                        <el-form-item label="模版名称" :required="false">
                            <el-select
                                :disabled="title == '修改包车价格模板设置' && add_data.templatesInfoId == '1' ? true : false"
                                v-model="add_data.templatesInfoId" placeholder="请选择模版" clearable>
                                <el-option v-for="item in findTemplatesInfoNameCombo_list" :key="item.id"
                                    :label="item.templates_name" :value="item.id" />
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="门店名称" :required="false">
                            <el-input style="width:220px" v-model="add_data.storeName" placeholder="请输入名店名称" clearable>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="门店地址" :required="false">
                            <el-input @click="map_off_btn" style="width:220px" v-model="add_data.storeAddress"
                                placeholder="请选择门店详情地址" clearable>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>


                <el-row>
                    <el-col :span="12">
                        <el-form-item label="座位数" :required="false">
                            <!-- <el-input type="number" style="width:220px" v-model="add_data.seats"
                                placeholder="请输入座位数eg:5" clearable>
                                <template #append>座</template>
                            </el-input> -->
                            <el-select @change='seats_change' v-model="add_data.seats" placeholder="请选择座位数">
                                <el-option v-for="item in seats_list" :key="item.value" :label="item.label"
                                    :value="item.value" />

                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="车辆配置" :required="true">
                            <el-select style="width:350px" @change='carConfigurationType_change'
                                v-model="add_data.carConfigurationType" placeholder="请选择车辆配置">
                                <el-option v-for="item in getCarConfigurationType_list" :key="item.id"
                                    :label="item.val + '(' + item.other + ')'" :value="item.id" />
                            </el-select>
                        </el-form-item>
                    </el-col>


                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="油耗" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.oilPrice"
                                placeholder="油耗 eg:2" clearable>
                                <template #append>元/公里</template>
                            </el-input>
                        </el-form-item>
                    </el-col>


                    <el-col :span="8">
                        <el-form-item label="包含公里数" :required="false">
                            <el-input type="number" v-model="add_data.baseKilo" placeholder="包含公里数 eg:30" clearable>
                                <template #append>公里</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="超公里数单价" :required="false">
                            <el-input type="number" v-model="add_data.moreBaseKiloPrice" placeholder="超公里数单价 eg:30"
                                clearable>
                                <template #append>元/公里</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>

                <el-row>
                    <el-col :span="8">
                        <el-form-item label="驾驶员日工资" :required="false">
                            <el-input type="number" v-model="add_data.driverDaySalary" placeholder="驾驶员日工资 eg:300"
                                clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="8">
                        <el-form-item label="司机工作时长" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.driverWorkHour"
                                placeholder="司机工作时长 eg:9" clearable>
                                <template #append>元</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="司机超时单价" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.driverMoreHourSalary"
                                placeholder="司机超时单价eg:50" clearable>
                                <template #append>元/小时</template>
                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="开票税费" :required="false">
                            <el-input type="number" style="width:220px" v-model="add_data.taxesRatio"
                                placeholder="开票税费 eg:2" clearable>
                                <template #append>%</template>
                            </el-input>
                        </el-form-item>
                    </el-col>

                    <el-col :span="15">
                        <el-form-item label="备注" :required="false">
                            <el-input v-model="add_data.note" placeholder="备注" clearable>

                            </el-input>
                        </el-form-item>
                    </el-col>
                </el-row>







            </el-form>
            <div style="margin-left:50vw;margin-top:8px;display:flex">
                <el-button v-if="title != '修改包车价格模板设置'" @click="ok_btn(1)" type="warning">保存并继续</el-button>
                <el-button @click="ok_btn(2)" type="primary">确认提交</el-button>
            </div>

        </el-dialog>

        <!-- 地图弹窗 -->
        <el-dialog style="margin-top:10vh;height:80vh;overflow: hidden;" v-model="map_off" title="门店地址:" width="80%"
            :close-on-click-modal='false'>
            <div class="div_map">
                <div class="map_input">
                    <el-input @input="map_change" id='tipinput' style="width:40%" v-model="map_address"
                        placeholder="请输入门店地址">
                        <template #prepend>门店地址:</template>
                    </el-input>
                    <el-button @click="map_ok_btn" type="primary">确认</el-button>
                </div>
                <div v-if="map_address_list.length > 0" class="map_input2">
                    <div style="width:40%;background:#fff;margin-left:20px;padding: 10px;font-weight: 700;">
                        <div @click="map_list_btn(item)" class="div_bg" v-for="(item, index) in map_address_list"
                            :key="index" style="margin-top: 10px;">
                            {{ item.district }}-{{ item.address }}-{{ item.name }}
                        </div>
                    </div>
                </div>
                <div id="myMap" style="height: 65vh; width: 100%">
                </div>
            </div>
        </el-dialog>


        <!-- 设置利润列表 -->
        <el-dialog style="margin-top:5vh;height:85vh;overflow: hidden;" v-model="BcProfitSet_off" title="利润列表:"
            width="90%" :close-on-click-modal='false'>
            <el-card>
                <template #header>
                    <!-- 搜索 -->
                    <div>
                        <el-date-picker :default-time="defaultTime" style="margin-left: 10px;width: 340px;"
                            v-model="timeTypeTime" @change="timeTypeTime_btn" type="datetimerange"
                            start-placeholder="开始时间" end-placeholder="结束时间" format="YYYY-MM-DD HH:mm:ss"
                            value-format="YYYY-MM-DD HH:mm:ss" />
                        <el-button style="margin-left: 20px;height:30px" @click="BcProfitSet_btn" type="primary"
                            icon="Search">搜索</el-button>
                    </div>
                    <!-- 功能按钮 -->
                    <div style="margin-top:10px;">
                        <el-button @click="BcProfitSet_add_btn" type="primary" icon="SuccessFilled">添加</el-button>
                        <el-button @click="BcProfitSet_up_btn" type="warning" icon="WarnTriangleFilled">修改</el-button>
                        <el-button @click="BcProfitSet_del_btn" type="danger" icon="CircleCloseFilled">删除</el-button>
                    </div>
                </template>
                <div>
                    <el-table @selection-change="selection_change_btn2" :data="BcProfitSet_list" border fit
                        height="60vh" style="width: 100%;margin-bottom: 20px;" :cell-style="cellStyle2">
                        <el-table-column type="selection" width="35" />
                        <el-table-column label="编号" width="55" fixed type="index" />
                        <!-- <el-table-column width="200" property="plateNum" label="车牌号">
    
                        <template #="{ row, column, $index }">
                            {{ row.seats + '座-' + row.plateNum }} <span v-if="row.isRestricted"
                                style="color:Red">(限号)</span><br>
                            <el-button @click="filterCar_data_ok_btn(row)" size="small" type="primary">派车</el-button>
                        </template>
                    </el-table-column> -->

                        <el-table-column property="startTime" label="开始时间" />
                        <el-table-column property="endTime" label="结束时间" />
                        <el-table-column property="monPrice" label="周一利润" />
                        <el-table-column property="tuesPrice" label="周二利润" />
                        <el-table-column property="wedPrice" label="周三利润" />
                        <el-table-column property="thurPrice" label="周四利润" />
                        <el-table-column property="friPrice" label="周五利润" />
                        <el-table-column property="satPrice" label="周六利润" />
                        <el-table-column property="sunPrice" label="周日利润" />

                    </el-table>
                </div>

                <!-- <div style="margin-top:20px">
                    <el-pagination @current-change="current_change_btn" @size-change="size_change_btn"
                        v-model:current-page="find_data.page.pageNum" v-model:page-size="find_data.page.pageSize"
                        :page-sizes="[20, 50, 100, 200]" :background="true"
                        layout="prev, pager, next, jumper,->,sizes,total," :total="total" />
                </div> -->
            </el-card>

            <el-dialog v-model="BcProfitSet_add_off" width="80%" :title="BcProfitSet_add_title" append-to-body>
                <el-form :model="BcProfitSet_add_data" label-width="140px" label-suffix="：">


                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="开始时间" :required="false">
                                <el-date-picker value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
                                    v-model="BcProfitSet_add_data.startTime" type="date" placeholder="请选开始时间" />
                            </el-form-item>
                        </el-col>

                        <el-col :span="12">
                            <el-form-item label="结束时间" :required="false">
                                <el-date-picker value-format="YYYY-MM-DD HH:mm:ss" format="YYYY-MM-DD HH:mm:ss"
                                    v-model="BcProfitSet_add_data.endTime" type="date" placeholder="请选结束时间" />
                            </el-form-item>
                        </el-col>

                    </el-row>


                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="周一利润" :required="false">
                                <el-input type="number" v-model="BcProfitSet_add_data.monPrice" placeholder="请输入周一利润"
                                    clearable>
                                    <template #append>元</template>
                                </el-input>

                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="周二利润" :required="false">
                                <el-input type="number" v-model="BcProfitSet_add_data.tuesPrice" placeholder="请输入周二利润"
                                    clearable>
                                    <template #append>元</template>
                                </el-input>

                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="周三利润" :required="false">
                                <el-input type="number" v-model="BcProfitSet_add_data.wedPrice" placeholder="请输入周三利润"
                                    clearable>
                                    <template #append>元</template>
                                </el-input>

                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="周四利润" :required="false">
                                <el-input type="number" v-model="BcProfitSet_add_data.thurPrice" placeholder="请输入周四利润"
                                    clearable>
                                    <template #append>元</template>
                                </el-input>

                            </el-form-item>
                        </el-col>


                    </el-row>
                    <el-row>
                        <el-col :span="6">
                            <el-form-item label="周五利润" :required="false">
                                <el-input type="number" v-model="BcProfitSet_add_data.friPrice" placeholder="请输入周五利润"
                                    clearable>
                                    <template #append>元</template>
                                </el-input>

                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="周六利润" :required="false">
                                <el-input type="number" v-model="BcProfitSet_add_data.satPrice" placeholder="请输入周六利润"
                                    clearable>
                                    <template #append>元</template>
                                </el-input>

                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="周日利润" :required="false">
                                <el-input type="number" v-model="BcProfitSet_add_data.sunPrice" placeholder="请输入周日利润"
                                    clearable>
                                    <template #append>元</template>
                                </el-input>

                            </el-form-item>
                        </el-col>


                    </el-row>







                </el-form>
                <div style="margin-left:65vw;margin-top:8px;display:flex">
                    <el-button v-if="BcProfitSet_add_title != '修改利润设置'" @click="BcProfitSet_add_ok_btn(1)"
                        type="warning">保存并继续</el-button>
                    <el-button @click="BcProfitSet_add_ok_btn(2)" type="primary">确认提交</el-button>
                </div>
            </el-dialog>



        </el-dialog>
    </div>
</template>

<script setup>
import Sortable from 'sortablejs';
import { ref, reactive, onMounted, computed } from 'vue'
import CircularJSON from 'circular-json'

import {
    getBcPriceTemplatesPages, getAreaSetList, getStationListPages, findTemplatesInfoNameCombo, getCarConfigurationType,
    adupBcPriceTemplates, delBcPriceTemplates, adupPrivateSet, getPrivateSetList, getCompanyCombo, getBcProfitSetPages,
    adupBcProfitSet, delBcProfitSet,
} from '@/api/system_management.js'
import { ElMessage, ElLoading, ElMessageBox } from 'element-plus'
import AMapLoader from "@amap/amap-jsapi-loader"
import { securityJsCode, key } from '@/utils/common.js'
onMounted(async () => {


    getPrivateSetList({
        find: '包车价格模板设置',
        page: {
            pageNum: 1,
            pageSize: 999,
        },
    }).then(res => {
        if (res.data.list[0]) {
            table_data_list_new.value = JSON.parse(res.data.list[res.data.list.length - 1].dat)
        } else {
            table_data_list_new.value = table_data_list
        }
    })


    Sortable.create(sortableContainer.value, {
        draggable: '.drag_it',
        ghostClass: 'sortable-ghost',
        onEnd: evt => {
            const targetRow = table_data_list_new.value.splice(evt.oldIndex, 1)[0];
            table_data_list_new.value.splice(evt.newIndex, 0, targetRow);

            // 重新赋值给列数组
            // let cols = that.U.scopy(that.fields);
            // let list = cols.filter(it => { return it.show; });
            // that.$emit('saveSet', {dgName: that.dgName, cols: list});
        }
    })


    await list_api()

    getAreaSetList({
        page: {
            pageNum: 1,
            pageSize: 999,
        },
        find: '',
    }).then(res => {
        getAreaSetList_list.value = res.data.list
    })

    getStationListPages({
        page: {
            pageNum: 1,
            pageSize: 999,
        },
        stationTypes: ['TRAIN', 'AIRPORT', 'BUS'],
    }).then(res => {
        if (res.code == 1) {
            getStationList_Data.value = res.data.list
        }
    })

    getCompanyCombo({ companyRole: "", find: "" }).then(res => {
        getCompanyCombo_list.value = res.data
    })

    findTemplatesInfoNameCombo({
        page: {
            pageNum: 1,
            pageSize: 999,
        },
        find: '',
    }).then(res => {
        findTemplatesInfoNameCombo_list.value = res.data.list
    })


})
const getCompanyCombo_list = ref([])
const seats_list = ref([
    {
        value: 5,
        label: '5座'
    },
    {
        value: 7,
        label: '7座'
    },
    {
        value: 9,
        label: '9座'
    },
    {
        value: 12,
        label: '12座'
    },
    {
        value: 14,
        label: '14座'
    },
    {
        value: 17,
        label: '17座'
    },

    {
        value: 23,
        label: '23座'
    },
    {
        value: 30,
        label: '30座'
    },
    {
        value: 39,
        label: '39座'
    },
    {
        value: 49,
        label: '49座'
    },
    {
        value: 55,
        label: '55座'
    },
])

const seats_change = () => {

    add_data.carConfigurationType = ''
    let luser = JSON.parse(localStorage.getItem("luser"))
    let luser_companyNum = luser.companyNum
    getCarConfigurationType({
        addWay: '0',
        seats: add_data.seats,
        companyNum: luser_companyNum,
    }).then(res => {
        getCarConfigurationType_list.value = res.data
    })
}
const carConfigurationType_change = () => {
    console.log(add_data.carConfigurationType)
    for (let i = 0; i < getCarConfigurationType_list.value.length; i++) {
        if (add_data.carConfigurationType == getCarConfigurationType_list.value[i].id) {
            add_data.carConfigurationSeries = getCarConfigurationType_list.value[i].other
        }
    }
}
const getCarConfigurationType_list2 = ref([])
const seats_change1 = () => {
    let luser = JSON.parse(localStorage.getItem("luser"))
    let luser_companyNum = luser.companyNum
    find_data.carConfigurationType = ''
    getCarConfigurationType({
        addWay: '0',
        seats: find_data.seats,
        companyNum: luser_companyNum,
    }).then(res => {
        getCarConfigurationType_list2.value = res.data
    })
}
const carConfigurationType_change1 = () => {
    for (let i = 0; i < getCarConfigurationType_list2.value.length; i++) {
        if (find_data.carConfigurationType == getCarConfigurationType_list2.value[i].id) {
            find_data.carConfigurationSeries = getCarConfigurationType_list2.value[i].other
        }
    }
}

//#region 地图
const myMap = ref('')
const geolocation = ref('') // 定位
const map_address = ref('')
const map_address_list = ref([])
const map_value = ref({})
const marker = ref('')
const map_off = ref(false)
const map_off_btn = () => {
    map_off.value = true
    // 地图
    window._AMapSecurityConfig = {
        securityJsCode: securityJsCode,
    }
    // 首次加载
    AMapLoader.load({
        key: key,
        version: '2.0',
        plugins: ['AMap.Driving', 'AMap.Geolocation', 'AMap.Scale', 'AMap.AutoComplete', 'AMap.PlaceSearch'],
    }).then((AMap) => {
        // 初始化-地图对象
        myMap.value = new AMap.Map('myMap', { zoom: 10, center: [104.065861, 30.657401] });
        myMap.value.addControl(new AMap.Scale())
        geolocation.value = new AMap.Geolocation({ //定位
            enableHighAccuracy: true, //是否使用高精度定位，默认:true
            convert: true, //自动偏移坐标 为高德坐标，默认：true
            timeout: 5000, //超过5秒后停止定位，默认：无穷大
            buttonPosition: 'RB', //定位按钮停靠位置
            showMarker: true, //定位成功在位置显示点标记，默认：true
        })
        myMap.value.addControl(geolocation.value)
        geolocation.value.getCurrentPosition((status, result) => {
            console.log('定位getCurrentPosition', status, result);
            if (status == 'complete') {
                console.log('定位信息', result);
            } else {
                console.log('定位出错', result);
            }
        })



    }).catch(err => { console.log('高德地图加载失败：', err); });
}
const map_change = () => {
    let autoOptions = {
        city: '成都市'
    }
    var autoComplete = new AMap.Autocomplete(autoOptions);
    autoComplete.search(map_address.value, function (status, result) {
        // 搜索成功时，result即是对应的匹配数据
        map_address_list.value = result.tips.slice(0, 5)
    })
}




const map_list_btn = (e) => {
    console.log(e)
    map_address.value = e.district + '-' + e.address + '-' + e.name
    map_value.value = e

    myMap.value.panTo([e.location.lng, e.location.lat]);
    if (marker.value) {
        myMap.value.remove(marker.value);
    }
    myMap.value.setFitView();
    marker.value = new AMap.Marker({
        map: myMap.value,
        position: [e.location.lng, e.location.lat],
    });
    myMap.value.setFitView();
    console.log(myMap.value)
    myMap.value.add(marker.value);


}
const map_ok_btn = () => {

    add_data.storeAddress = map_value.value.district + map_value.value.address + map_value.value.name

    add_data.storeLnglat = map_value.value.location.lng + ',' + map_value.value.location.lat

    map_off.value = false

}
//#endregion

//#region 表格数据处理
const table_data_list = reactive([
    { label: '模板名称', field: 'templatesInfoId', width: 100, off: true },
    { label: '门店名称', field: 'storeName', width: 150, off: true },

    { label: '座位数', field: 'seats', width: 100, off: true },
    { label: '车辆配置', field: 'carConfigurationType', width: 100, off: true },
    { label: '包含公里数', field: 'baseKilo', width: '120', off: true },
    { label: '超公里数单价（元/公里）', field: 'moreBaseKiloPrice', width: '200', off: true },
    { label: '驾驶员日工资（元）', field: 'driverDaySalary', width: '170', off: true },
    { label: '司机工作时长（小时）', field: 'driverWorkHour', width: '170', off: true },
    { label: '司机超时单价（元/小时）', field: 'driverMoreHourSalary', width: '200', off: true },
    { label: '油耗', field: 'oilPrice', width: '', off: true },
    { label: '门店详细地址', field: 'storeAddress', width: 400, off: true },
    { label: '备注', field: 'note', width: '400', off: true },

    { label: '添加时间', field: 'addTime', width: 165, off: true },
])

const table_data_list_new = ref([])
const icon_off = ref(false)
// 创建排序容器的引用
const sortableContainer = ref('')

const icon_btn = () => {
    icon_off.value = !icon_off.value
    console.log(sortableContainer.value)

}
const resetTableSet = () => {
    console.log(table_data_list)
    table_data_list_new.value = JSON.parse(JSON.stringify(table_data_list))
    console.log(table_data_list)
    console.log(table_data_list_new.value)
}
const saveTableSet = () => {
    adupPrivateSet({
        dat: JSON.stringify(table_data_list_new.value),
        tbName: '包车价格模板设置',
        tbNum: "bcPriceTemplates",
    }).then(res => {
        if (res.code == 1) {
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
    icon_off.value = false
}

const checkbox_btn = (e, c) => {
    for (let i = 0; i < table_data_list_new.value.length; i++) {
        if (table_data_list_new.value[i].label == c.target._value) {
            table_data_list_new.value[i].off == e

        }

    }

}

const sortedItems = computed(() => {
    return [...table_data_list_new.value].sort((a, b) => a.id - b.id);
})
//#endregion



//#region 分页列表
const list_data = ref([])
const find_data = reactive({
    page: {
        pageNum: 1,
        pageSize: 20,
    },
    carConfigurationType: '',
    companyNum: '',
    seats: "",
    templatesInfoId: '',
    storeName: '',

})
const total = ref(0)

// 分页器一夜显示多少数据页面
const size_change_btn = () => {
    find_data.page.pageNum = 1
    list_api()
}

// 分页器跳转页面
const current_change_btn = () => {
    list_api()
}

const list_api = () => {

    getBcPriceTemplatesPages(find_data).then(res => {
        list_data.value = res.data.list
        total.value = res.data.total
    })
}
//#endregion

//#region 添加
const add_off = ref(false)
const findTemplatesInfoNameCombo_list = ref([])
const getAreaSetList_list = ref([])
const getStationList_Data = ref([])
const getCarConfigurationType_list = ref([])

const title = ref('添加包车价格模板设置')
const add_data = reactive({
    id: "",
    baseKilo: "",
    carConfigurationSeries: "",
    carConfigurationType: "",
    driverDaySalary: "",
    driverMoreHourSalary: "",
    driverWorkHour: "",
    moreBaseKiloPrice: "",
    note: "",
    oilPrice: "",
    seats: "",
    storeAddress: "",
    storeLnglat: "",
    storeName: "",
    taxesRatio: "",
    templatesInfoId: "",

})


const add_btn = () => {

    title.value = '添加包车价格模板设置'
    add_data.id = ''
    add_data.baseKilo = ''
    add_data.carConfigurationSeries = ''
    add_data.carConfigurationType = ''
    add_data.driverDaySalary = ''
    add_data.driverMoreHourSalary = ''
    add_data.driverWorkHour = ''
    add_data.moreBaseKiloPrice = ''
    add_data.note = ''
    add_data.oilPrice = ''
    add_data.seats = ''
    add_data.storeAddress = ''
    add_data.storeLnglat = ''
    add_data.storeName = ''
    add_data.taxesRatio = ''
    add_data.templatesInfoId = ''


    add_off.value = true

}


//#endregion

//#region 表格选择
const table_list = ref([])
const selection_change_btn = (e) => {
    table_list.value = e
    console.log(e)
}
//#endregion
//#region 修改
const up_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }


    title.value = '修改包车价格模板设置'

    add_data.id = table_list.value[0].id
    add_data.baseKilo = table_list.value[0].baseKilo
    add_data.carConfigurationSeries = table_list.value[0].carConfigurationSeries
    add_data.carConfigurationType = table_list.value[0].carConfigurationType
    add_data.driverDaySalary = table_list.value[0].driverDaySalary
    add_data.driverMoreHourSalary = table_list.value[0].driverMoreHourSalary
    add_data.driverWorkHour = table_list.value[0].driverWorkHour
    add_data.moreBaseKiloPrice = table_list.value[0].moreBaseKiloPrice
    add_data.note = table_list.value[0].note
    add_data.oilPrice = table_list.value[0].oilPrice
    add_data.seats = table_list.value[0].seats
    add_data.storeAddress = table_list.value[0].storeAddress
    add_data.storeLnglat = table_list.value[0].storeLnglat
    add_data.storeName = table_list.value[0].storeName
    add_data.taxesRatio = table_list.value[0].taxesRatio

    for (let i = 0; i < findTemplatesInfoNameCombo_list.value.length; i++) {
        if (findTemplatesInfoNameCombo_list.value[i].templates_name == table_list.value[0].templatesInfoId) {
            add_data.templatesInfoId = findTemplatesInfoNameCombo_list.value[i].id
        }
    }


    add_data.carConfigurationType = table_list.value[0].carConfigurationType


    let luser = JSON.parse(localStorage.getItem("luser"))
    let luser_companyNum = luser.companyNum
    getCarConfigurationType({
        addWay: '0',
        seats: add_data.seats,
        companyNum: luser_companyNum,
    }).then(res => {
        getCarConfigurationType_list.value = res.data
    })
    add_off.value = true
}
//#endregion

// 提交
const ok_btn = (e) => {
    // 定义要比较的两个时间
    //let time1 = add_data.nightOneEtime
    //let time2 = add_data.nightTwoStime
    // 转换时间为分钟数
    //let time1Minutes = convertToMinutes(time1);
    //let time2Minutes = convertToMinutes(time2);
    // 比较时间大小
    //if (time2Minutes < time1Minutes) {
    //return ElMessage({
    //message: '夜班2开始时间不能小于夜班1结束时间',
    //type: 'warning',
    //})
    //}
    if (!add_data.carConfigurationType) {
        return ElMessage({
            message: '请选择车辆配置',
            type: 'warning',
        })
    }


    adupBcPriceTemplates(add_data).then(res => {
        if (res.code == 1) {
            list_api()
            if (e == 2 || title.value == '修改顺风车价格模板设置') {
                add_off.value = false
            }
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}
//#region 删除
const del_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }

    ElMessageBox.confirm(
        '是否确认删除?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {
            if (table_list.value[0].templatesInfoId == '基础模版') {
                return ElMessage({
                    message: '基础模版不能删除，只能修改',
                    type: 'warning',
                })
            } else {
                delBcPriceTemplates({
                    ids: [table_list.value[0].id]
                }).then(res => {
                    if (res.code == 1) {
                        list_api()
                        return ElMessage({
                            message: res.msg,
                            type: 'success',
                        })
                    } else {
                        return ElMessage({
                            message: res.msg,
                            type: 'warning',
                        })
                    }
                })
            }



        })
        .catch((e) => {
            if (e == 'cancel') {
                ElMessage({
                    type: 'warning',
                    message: '取消删除成功',
                })
            }

        })

}
//#endregion

//#region 设置包车利润
const BcProfitSet_list = ref([])
const BcProfitSet_off = ref(false)
const BcProfitSet_find = ref({
    bcPriceTemplatesId: '',
    startTime: '',
    endTime: '',
})
const table_list2 = ref([])
const selection_change_btn2 = (e) => {
    table_list2.value = e
    console.log(e)
}
const BcProfitSet_btn = () => {
    if (table_list.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }
    BcProfitSet_find.value.bcPriceTemplatesId = table_list.value[0].id
    getBcProfitSetPages(BcProfitSet_find.value).then(res => {
        if (res.code == 1) {

            BcProfitSet_add_data.bcPriceTemplatesId = table_list.value[0].id
            BcProfitSet_list.value = res.data
            BcProfitSet_off.value = true
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}

const defaultTime = [new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]
const timeTypeTime = ref([])
const timeTypeTime_btn = (e) => {
    if (e) {
        timeTypeTime.value = e
        BcProfitSet_find.value.startTime = timeTypeTime.value[0]
        BcProfitSet_find.value.endTime = timeTypeTime.value[1]

    } else {
        timeTypeTime.value = ''
        BcProfitSet_find.value.startTime = ''
        BcProfitSet_find.value.endTime = ''
    }
}

const BcProfitSet_add_title = ref('添加利润设置')
const BcProfitSet_add_off = ref(false)
const BcProfitSet_add_data = reactive({
    bcPriceTemplatesId: '',
    startTime: '',
    endTime: '',
    friPrice: '',
    monPrice: '',
    satPrice: '',
    sunPrice: '',
    thurPrice: '',
    tuesPrice: '',
    wedPrice: '',
    id: '',
})
const BcProfitSet_add_btn = () => {
    BcProfitSet_add_title.value = '添加利润设置'
    BcProfitSet_add_data.startTime = ''
    BcProfitSet_add_data.endTime = ''
    BcProfitSet_add_data.friPrice = ''
    BcProfitSet_add_data.monPrice = ''
    BcProfitSet_add_data.satPrice = ''
    BcProfitSet_add_data.sunPrice = ''
    BcProfitSet_add_data.thurPrice = ''
    BcProfitSet_add_data.tuesPrice = ''
    BcProfitSet_add_data.wedPrice = ''
    BcProfitSet_add_data.id = ''
    BcProfitSet_add_off.value = true

}

const BcProfitSet_up_btn = () => {
    if (table_list2.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }
    BcProfitSet_add_title.value = '修改利润设置'
    BcProfitSet_add_data.id = table_list2.value[0].id
    BcProfitSet_add_data.startTime = table_list2.value[0].startTime
    BcProfitSet_add_data.endTime = table_list2.value[0].endTime
    BcProfitSet_add_data.friPrice = table_list2.value[0].friPrice
    BcProfitSet_add_data.monPrice = table_list2.value[0].monPrice
    BcProfitSet_add_data.satPrice = table_list2.value[0].satPrice
    BcProfitSet_add_data.sunPrice = table_list2.value[0].sunPrice
    BcProfitSet_add_data.thurPrice = table_list2.value[0].thurPrice
    BcProfitSet_add_data.tuesPrice = table_list2.value[0].tuesPrice
    BcProfitSet_add_data.wedPrice = table_list2.value[0].wedPrice
    BcProfitSet_add_off.value = true
}
const BcProfitSet_add_ok_btn = (e) => {

    adupBcProfitSet(BcProfitSet_add_data).then(res => {
        if (res.code == 1) {
            BcProfitSet_btn()
            if (e == 2 || title.value == '修改利润设置') {
                BcProfitSet_add_off.value = false
            }
            return ElMessage({
                message: res.msg,
                type: 'success',
            })
        } else {
            return ElMessage({
                message: res.msg,
                type: 'warning',
            })
        }
    })
}


const BcProfitSet_del_btn = () => {
    if (table_list2.value.length != 1) {
        return ElMessage({
            message: '请选择一条数据！',
            type: 'warning',
        })
    }

    ElMessageBox.confirm(
        '是否确认删除?',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
            distinguishCancelAndClose: 'true',
        }
    )
        .then(() => {
            delBcProfitSet({
                ids: [table_list2.value[0].id]
            }).then(res => {
                if (res.code == 1) {
                    BcProfitSet_btn()
                    return ElMessage({
                        message: res.msg,
                        type: 'success',
                    })
                } else {
                    return ElMessage({
                        message: res.msg,
                        type: 'warning',
                    })
                }
            })



        })
        .catch((e) => {


        })

}

//#endregion





//#region 搜索
const search_btn = () => {
    list_api()
}
//#endregion
</script>

<style scoped lang='scss'>
.div_map {
    position: relative;
    left: 0;
    top: 0;
}

.map_input {
    width: 100%;
    position: absolute;
    z-index: 1;
    display: flex;
    justify-content: center;

}

.map_input2 {
    width: 100%;
    position: absolute;
    z-index: 1;
    display: flex;
    justify-content: center;
    top: 34px;

}

.div_bg:hover {


    background-color: darkgray;
}
</style>
<style>
.col-items::-webkit-scrollbar {
    width: 5px !important;
}

.col-items>label {
    margin-left: 0px !important;
    margin-top: 5px;
    width: 100%;
}

.el-table .el-table__cell {
    padding: 0px !important;
}
</style>
